//
//  LandmarkList.swift
//  ChinaLandmarkDemo
//
//  Created by liy on 2025/2/10.
//

import SwiftUI

struct LandmarkList: View {
  @State var showFavoriteOnly = false
	@EnvironmentObject var userData: UserData
	
	var body: some View {
    NavigationView {
      List {
        Toggle(isOn: $showFavoriteOnly) {
          Text("只展示收藏")
        }
				ForEach(userData.userLandmarks) { landmark in

          if !showFavoriteOnly {
            NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
              LandmarkCell(landmark: landmark)
            }
          } else if landmark.isFavorite {
            NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
              LandmarkCell(landmark: landmark)
            }
          }
        }
      }
      .navigationBarTitle("中国地标", displayMode: .automatic)
      .listStyle(.plain)
    }
  }
}

#Preview {
  LandmarkList()
		.environmentObject(UserData())
}
